class MovingBackground extends CanvasWindow{
  Sprite BG1, BG2;
  int speed = 2;
  
  MovingBackground(num bgWidth, num bgHeight):super(new Element.tag('canvas'))
  {
    element.width = bgWidth;
    element.height = bgHeight;
    
    BG1 = new Sprite('img/spaceBG.gif');    
    BG2 = new Sprite('img/spaceBG.gif');
    
    addChild(BG1);
    addChild(BG2);
  }
  
  void onNewParent()
  {
    BG2.setX(BG1.width);
  }
  
  void update(int time)
  {
    BG1.incX(-speed);
    BG2.incX(-speed);
    
    if(BG2.getX() <= 0)
    {
      BG2.setX(BG1.width);
      BG1.setX(0);
    }
  }
  
}
